b<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">
<title>地址管理</title>
<link href="../static/css/admin.css" rel="stylesheet" type="text/css">
<link href="../static/css/amazeui.css" rel="stylesheet" type="text/css">
<link href="../static/css/personal.css" rel="stylesheet" type="text/css">
<link href="../static/css/addstyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../static/js/amazeui.js"></script>
<script type="text/javascript" src="../static/js/myinit.js"></script>
<script type="text/javascript" src="../static/js/quyu.js"></script>
</head>

<body>
<!--头 -->
<header>
  <article>
    <div class="mt-logo"> 
      <!--顶部导航条 -->
      <div class="am-container header">
        <ul class="message-l">
          <div class="topMessage">
            <div class="menu-hd"> <a href="#" target="_top" class="h">亲，请登录</a> <a href="#" target="_top">免费注册</a> </div>
          </div>
        </ul>
        <ul class="message-r">
          <div class="topMessage home">
            <div class="menu-hd"><a href="#" target="_top" class="h">商城首页</a></div>
          </div>
          <div class="topMessage my-shangcheng">
            <div class="menu-hd MyShangcheng"><a href="#" target="_top"><i class="am-icon-user am-icon-fw"></i>个人中心</a></div>
          </div>
          <div class="topMessage mini-cart">
            <div class="menu-hd"><a id="mc-menu-hd" href="#" target="_top"><i class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span><strong id="J_MiniCartNum" class="h">0</strong></a></div>
          </div>
          <div class="topMessage favorite">
            <div class="menu-hd"><a href="#" target="_top"><i class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>
          </div>
        </ul>
      </div>
      
      <!--悬浮搜索框-->
      
      <div class="nav white">
        <div class="logoBig">
          <li><img src="../static/img/logobig.png" /></li>
        </div>
        <div class="search-bar pr"> <a name="index_none_header_sysc" href="#"></a>
          <form>
            <input id="searchInput" name="index_none_header_sysc" type="text" placeholder="搜索" autocomplete="off">
            <input id="ai-topsearch" class="submit am-btn" value="搜索" index="1" type="submit">
          </form>
        </div>
      </div>
      <div class="clear"></div>
    </div>
  </article>
</header>
<div class="nav-table">
  <div class="long-title"><span class="all-goods">全部分类</span></div>
  <div class="nav-cont">
    <ul>
      <li class="index"><a href="#">首页</a></li>
      <li class="qc"><a href="#">闪购</a></li>
      <li class="qc"><a href="#">限时抢</a></li>
      <li class="qc"><a href="#">团购</a></li>
      <li class="qc last"><a href="#">大包装</a></li>
    </ul>
    <div class="nav-extra"> <i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的优惠券<i class="am-icon-angle-right" style="padding-left: 10px;"></i> </div>
  </div>
</div>
<b class="line"></b>
<div class="center">
  <div class="col-main">
    <div class="main-wrap">
      <div class="user-address"> 
        <!--标题 -->
        <div class="am-cf am-padding">
          <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">地址管理</strong> / <small>Address&nbsp;list</small></div>
        </div>
        <hr/>
        <ul class="am-avg-sm-1 am-avg-md-3 am-thumbnails" id="list">
          
        </ul>
        <div class="clear"></div>
        <a class="new-abtn-type" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">添加新地址</a> 
        <!--例子-->
        <div class="am-modal am-modal-no-btn" id="doc-modal-1">
          <div class="add-dress"> 
            
            <!--标题 -->
            <div class="am-cf am-padding">
              <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add&nbsp;address</small></div>
            </div>
            <hr/>
            <div class="am-u-md-12 am-u-lg-8" style="margin-top: 20px;">
              <form class="am-form am-form-horizontal">
                <div class="am-form-group">
                  <label for="user-name" class="am-form-label">收货人</label>
                  <div class="am-form-content">
                    <input type="text" id="user-name" placeholder="收货人">
                  </div>
                </div>
                <div class="am-form-group">
                  <label for="user-phone" class="am-form-label">手机号码</label>
                  <div class="am-form-content">
                    <input id="user-phone" placeholder="手机号必填" type="email">
                  </div>
                </div>
                <div class="am-form-group">
                  <label for="user-address" class="am-form-label">所在地</label>
                  <div class="am-form-content address">
                    <select id="selProvince2" name="selProvince2"></select>
					  
					
					<select id="selCity2" name="selCity2"></select>
					 
					
					<select id="selArea2" name="selArea2"></select>
					 
                  </div>
                </div>
                <div class="am-form-group">
                  <label for="user-intro" class="am-form-label">详细地址</label>
                  <div class="am-form-content">
                    <textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
                    <small>100字以内写出你的详细地址...</small> </div>
                </div>
                <div class="am-form-group">
                  <div class="am-u-sm-9 am-u-sm-push-3"> <a class="am-btn am-btn-danger" id="cmf">保存</a></div>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <script type="text/javascript">
		$(document).ready(function() {							
			$(".new-option-r").click(function() {
				$(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
			});
			
			var $ww = $(window).width();
			if($ww>640) {
				$("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
			}
			
		})
	</script>
      <div class="clear"></div>
    </div>
    <!--底部-->
    <div class="footer ">
      <div class="footer-hd">
        <p><img src="../static/img/duo.png" style="width:25px" />品类齐全<b>|</b><img src="../static/img/kuai.png" style="width:25px" />多仓直发<b>|</b><img src="../static/img/hao.png" style="width:25px" />正品行货<b>|</b><img src="../static/img/sheng.png" style="width:25px" />天天低价</p>
      </div>
      <div class="footer-bd "> </div>
    </div>
  </div>
  <aside class="menu">
    <ul>
      <li class="person active"> <a>个人中心</a> </li>
      <li class="person"> <a href="#" id="tomyorders">我的订单</a>
  
      </li>
      <li class="person"> <a href="#" id="wodeshoucang">我的收藏</a>
 
      </li>
      <li class="person"> <a href="#" id="chengweihuiyuan">成为会员</a>

      </li>
      <li class="person"> <a href="#" id="youhuiquan">优惠卡券</a>

      </li>
       <li class="person"> <a href="#" id="xianjinzhanghu">我的充值</a>
  
      </li>
      <li class="person"> <a href="#" id="shouhuodizhi">收货地址</a>
 
      </li>
    </ul>
  </aside>
</div>
<script type="text/javascript">
var id=-1;
var openid =getUrldata('OPENID');
$('.mypageback').click(function(){
	window.history.go(-1);
});
$('#chengweihuiyuan').click(function(e) {
	document.location.href="register_pc.html?OPENID="+openid;
});
$('#wodeshoucang').click(function(e){
	document.location.href="collection_pc.html?OPENID="+openid;
});
$('#youhuiquan').click(function(e) {
	document.location.href="coupon_pc.html?OPENID="+openid;
});

$('#tomyorders').click(function(){
	window.location.href="order_pc.html?code="+code;
});

$('#shouhuodizhi').click(function(){
	document.location.href="address_pc.html?OPENID="+openid;

});
$('#xianjinzhanghu').click(function(){
	document.location.href="bonus_pc.html?OPENID="+openid;
});
function initlist(){
	var url ='/webserver/api/v1/custadr/?format=json&wx_id='+openid;
	$.getJSON(url,function(rs){
		var objects=rs.objects;
		if(objects!=null&&objects!=undefined&&objects.length>0){
			$.each(objects,function(index,item){
				$('#list').append('<li class="user-addresslist" id="'+item.id+'"><p class="new-tit new-p-re"> <span class="new-txt">'+item.custname+'</span> <span class="new-txt-rd2">'+item.phoneno+'</span> </p><div class="new-mu_l2a new-p-re"><p class="new-mu_l2cw"> <span class="title">地址：</span><span class="street">'+item.cityname+item.detailAdrinfo+'</span></p></div><div class="new-addr-btn" id="drdd-info7"><a class="mybtn_del"><i class="am-icon-trash"></i>删除</a> </div></li>');
			});
			$('.user-addresslist').each(function(index,item){
				var id=$(this).attr('id');
				$(this).find('.mybtn_del').click(function(){
					var bb=[];
					var aa={};
					aa.NAME="确认";
					aa.ACTION=function(){
						delAAddr(id);
					};
					
					bb.push(aa);
					aa={};
					aa.NAME="取消";
					aa.ACTION=function(){
						
					};
					bb.push(aa);
					toastwithactions("确认删除?",bb);
				});
			});
		}
	});
}

$(document).ready(function(){
	initlist();
});

$('#toadddizhi').click(function(){
	document.location.href="xinzengshouhuo.html?OPENID="+openid;
});

function delAAddr(id){
	var url = "/shop/api/deladdress/?id="+id;
	$.post(url,{"id":id},function(rs){
		console.log(rs);
		if(rs){
			$('#'+id).remove();
		}
	},'json');	
}

$('#cmf').click(function(){
		addOne();
	});
function addOne(){
	var url = "/webserver/api/v1/custadr/";
	var aa={};
	aa.cityname=$('#selProvince2 option:checked').html()+$('#selCity2 option:checked').html()+$('#selArea2 option:checked').html();
	if(aa.cityname==''){
		alert('请输入所在省份城市与区域');
		return;
	}
	aa.custname=$('#user-name').val();
	if(aa.custname==''){
		alert('姓名不能为空');
		return;
	}
	aa.detailAdrinfo=$('#user-intro').val();
	if(aa.detailAdrinfo==''){
		alert('地址不能为空');
		return;
	}
	aa.phoneno=$('#user-phone').val();
	if(aa.phoneno==''&&aa.phoneno.length!=11){
		alert('手机必须为11位的');
		return;
	}
	aa.wx_id=openid;
	dopost(url,aa,function(rs){
		if(rs.id!=null&&rs.id!=undefined&&rs.id!='null'&&rs.id!='undefined'){
			alert('添加成功');
			window.history.go(-1);
			
		}

	});
	

}


var b = AreaSelector({
selProvinceId:'selProvince2',
selCityId:'selCity2',
selAreaId:'selArea2',
onProvinceChange:function(){
	//alert(this.options[this.selectedIndex].value);
},
onCityChange:function(){
	//alert(this.options[this.selectedIndex].value);
},
onAreaChange:function(){
	//alert(this.options[this.selectedIndex].value);
}});
b.initProvince(9,1,5);
</script>
</body>
</html>